home *** CD-ROM | disk | FTP | other *** search
- /****i* SOURCE_FILE/INFO
- *
- * NAME
- * PublishServer.js
- *
- * USAGE
- * Part of WPS JavaScript Library.
- *
- * COPYRIGHT
- * Copyright ⌐ 2000-2001 Website Pros, Inc.
- * All Rights Reserved.
- *
- * This is an unpublished work protected by Website Pros, Inc.
- * as a trade secret, and is not to be used or disclosed except as
- * expressly provided in a written license agreement executed by
- * you and Website Pros, Inc.
- *
- * <copyright@websitepros.com>
- *
- * NOTES
- * JavaScript code.
- *
- *****/
- if (!IS.isModuleInitialized("IS.NOF.PUBLISH.PublishServer"))
- {
- /**
- * Class PublishServer
- *
- * External dependencies: NOF.XML.XmlDocument, NOF.UTIL.ResourceBundle, NOF.UTIL.DefaultLocale
- **/
- function NOF_PublishServer(/*PublishServer*/ pServer) {
- this.__proto__ = NOF_PublishServer.prototype;
-
- if (typeof(pServer) != 'string') {
- this.pPublishServer = pServer;
- this.global = false;
- } else {
- //NOF.util_logging_ConsoleLogger_global.info("PublishSeerver.GlobalInit : " + pServer);
- this.publishProfile = new NOF.PUBLISHSETTINGS.PublishConfigFile(pServer);
- this.publishProfile.loadConfigFile();
- //this.publishProfile.setName(pServer);
- this.global = true;
- //NOF.util_logging_ConsoleLogger_global.info("PublishSeerver.GlobalInit : " + this.getName());
- }
-
- this.xmlAdvProp = NOF.XML.XmlDocument.create();
- this.xmlAdvProp.loadXML( this.getAdvancedSettings() );
-
- this.typeLabel = null;
- }
- {
- var members = NOF_PublishServer.prototype;
- members.CLASS_NAME = "PublishServer";
-
- members.ADVANCED_SETTINGS = "advancedsettings";
- members.VIRTUAL_FOLDERS = "virtualFolders";
-
- // Flag to show if server settings have been modified
- members.isModified = false;
-
- var methods = NOF_PublishServer.prototype;
-
- /**
- * Name of the published home page.
- **/
- methods.getHomePageName = function () {
- if (this.isGlobal())
- return this.publishProfile.getHomePageName();
- else
- return this.pPublishServer.HomePageName;
- }
- methods.setHomePageName = function (/*int*/ pageID) {
- if (this.isGlobal()) {
- this.publishProfile.setHomePageName(pageID);
- this.publishProfile.saveConfigFile();
- } else {
- this.pPublishServer.HomePageName = pageID;
- }
- }
-
- /**
- * Default HTML file extension.
- **/
- methods.getHTMLFileExtension = function () {
- if (this.isGlobal())
- return this.publishProfile.getFileExtension();
- else
- return this.pPublishServer.HTMLFileExt;
- }
- /**
- * Default HTML file extension.
- **/
- methods.setHTMLFileExtension = function (extension) {
- if (this.isGlobal()) {
- this.publishProfile.setFileExtension(extension);
- this.publishProfile.saveConfigFile();
- } else {
- this.pPublishServer.HTMLFileExt = extension;
- }
- }
-
- /**
- * Name of the publish server, is unique within a site.
- **/
- methods.getName = function () {
- if (this.isGlobal())
- return this.publishProfile.getName();
- else
- return this.pPublishServer.Name;
- }
- /**
- * Name of the publish server, is unique within a site.
- **/
- methods.setName = function (name) {
- if (this.isGlobal()) {
- this.publishProfile.setName(name);
- this.publishProfile.saveConfigFile();
- } else {
- this.pPublishServer.SetName(name);
- }
- }
-
- /**
- * URL of publish server
- **/
- methods.getURL = function () {
- if (this.isGlobal())
- return this.publishProfile.getURL();
- else
- return this.pPublishServer.URL;
- }
- /**
- * URL of publish server
- **/
- methods.setURL = function (url) {
- if (this.isGlobal()) {
- this.publishProfile.setURL(url);
- this.publishProfile.saveConfigFile();
- } else {
- this.pPublishServer.URL = url;
- }
- }
-
- /**
- * type of server (protocol): local, ftp, webdav, etc
- **/
- methods.getType = function () {
- if (this.isGlobal())
- return this.publishProfile.getType();
- else
- return this.pPublishServer.ServerType;
- }
- /**
- * type of server (protocol): local, ftp, webdav, etc
- **/
- methods.setType = function (type) {
- var oldType = this.getType();
- if (type != oldType) {
- if (this.isGlobal()) {
- this.publishProfile.setType(type);
- this.publishProfile.saveConfigFile();
- } else {
- this.pPublishServer.ServerType = type;
- }
-
- this.typeLabel = null;
- }
- }
-
- methods.getTypeLabel = function () {
- if (this.typeLabel == null) {
- var type = this.getType();
- var rs = NOF.UTIL.ResourceBundle.getBundle("PublishSettings/" + type + "/" + type, NOF.UTIL.DefaultLocale);
- this.typeLabel = rs.getProperty("publishServer.type.Label");
- }
- return this.typeLabel;
- }
-
- methods.isGlobal = function () {
- return this.global;
- }
-
- /**
- * @return true if the profile is a local profile and
- * it has an associated global profile
- **/
- methods.hasGlobalProfile = function () {
- if (this.isGlobal()) return false;
- return this.pPublishServer.HasGlobalProfile();
- }
-
- /**
- * @return true if the profile is a local profile and
- * it has a newer global profile associated.
- **/
- methods.isGlobalNewer = function () {
- if (this.isGlobal()) return false; //! throw new NOF.UTIL.Exception();
- return this.pPublishServer.IsGlobalNewer();
- }
-
- /**
- * @return the name of the global profile associated if the profile is a local profile,
- * or null if it is a global profile.
- **/
- methods.getGlobalFileName = function () {
- if (this.isGlobal()) return null; //throw new NOF.UTIL.Exception();
- return this.pPublishServer.GlobalFileName;
- }
-
-
- methods.test = function () {
- if (!this.isGlobal()) {
- //NOF.util_logging_ConsoleLogger_global.info("PublishServer.Test - Global isRemote: ");// + this.pPublishServer.SaveGlobal("GlProf" + this.getName()));
- //return this.pPublishServer.SaveGlobal("GlProf" + this.getName());
- var testResult = this.pPublishServer.Test();
- log.info(" testResult = " + testResult, "PublishServer", "test");
- return testResult;
- } else
- return false;
- }
-
- /**
- * True if this is a local publish server, false if remote server.
- **/
- methods.isLocalType = function () {
- if (this.isGlobal())
- return ((this.publishProfile.getType() == 'local') ? true : false);
- else
- return (this.pPublishServer.UseLocal);
- }
-
- /**
- * base directory on remote server (null for local)
- **/
- methods.getBaseDirectory = function () {
- if (this.isGlobal())
- return this.publishProfile.getBaseDirectory();
- else
- return this.pPublishServer.BaseDirectory;
- }
- /**
- * base directory on remote server (null for local)
- **/
- methods.setBaseDirectory = function (directory) {
- if (this.isGlobal()) {
- this.publishProfile.setBaseDirectory(directory);
- this.publishProfile.saveConfigFile();
- } else {
- this.pPublishServer.BaseDirectory = directory;
- }
- }
-
- /**
- * UserName: user name for connection to remote server (null for local)
- **/
- methods.getUserName = function () {
- if (this.isGlobal())
- return this.publishProfile.getUserName();
- else
- return this.pPublishServer.UserName;
- }
- /**
- * UserName: user name for connection to remote server (null for local)
- **/
- methods.setUserName = function (name) {
- if (this.isGlobal()) {
- this.publishProfile.setUserName(name);
- this.publishProfile.saveConfigFile();
- } else {
- this.pPublishServer.UserName = name;
- }
- }
-
- /**
- * Password for connection to remote server.
- **/
- methods.getPassword = function () {
- //throw new NOF.UTIL.Exception("invalid method call");
- //return '********';
- if (this.isGlobal())
- return this.publishProfile.getPassword();
- else
- return this.pPublishServer.Password;
- }
- /**
- * Password for connection to remote server.
- **/
- methods.setPassword = function (pswd) {
- if (this.isGlobal()) {
- this.publishProfile.setPassword(pswd);
- this.publishProfile.saveConfigFile();
- } else {
- this.pPublishServer.Password = pswd;
- }
- }
-
- /**
- * Advanced Settings of publish server
- **/
- methods.getAdvancedSettings = function () {
- if (this.isGlobal()) {
- var sStr = this.publishProfile.getAdvancedSettings();
- if (sStr == null) sStr = "";
- sStr = "<" + this.ADVANCED_SETTINGS + ">" + sStr +
- "</" + this.ADVANCED_SETTINGS + ">";
-
- //NOF.util_logging_ConsoleLogger_global.info("PublishServer.GetAdvSet : " + sStr);
- return new NOF.PUBLISH.AdvancedSettings(sStr);
- } else {
- if ((this.pPublishServer.AdvancedSettings == null) ||
- ("" == this.pPublishServer.AdvancedSettings)) {
- this.pPublishServer.AdvancedSettings = "<"
- + this.ADVANCED_SETTINGS + ">" +
- "</" + this.ADVANCED_SETTINGS + ">";
- }
-
- return new NOF.PUBLISH.AdvancedSettings(this.pPublishServer.AdvancedSettings);
- }
- }
- /**
- * Advanced Settings of publish server
- **/
- methods.setAdvancedSettings = function (/*AdvancedSettings*/ advancedSettings) {
- var advSetStr = advancedSettings.toXML();
- if (this.isGlobal()) {
- //NOF.util_logging_ConsoleLogger_global.info("Save aliases: 1: " + advSetStr);
- if ((advSetStr != null) && ("" != advSetStr)) {
- var sStr = "<" + this.ADVANCED_SETTINGS + ">";
- var idx = advSetStr.indexOf(sStr);
- if (idx >= 0) {
- advSetStr = advSetStr.substring(idx + sStr.length, advSetStr.length);
- }
-
- sStr = "</" + this.ADVANCED_SETTINGS + ">";
- idx = advSetStr.indexOf(sStr);
- if (idx >= 0) {
- advSetStr = advSetStr.substring(0, idx);
- }
- //NOF.util_logging_ConsoleLogger_global.info("Save aliases: 2: " + advSetStr);
- }
-
- this.publishProfile.setAdvancedSettings(advSetStr);
- //NOF.util_logging_ConsoleLogger_global.info("Save aliases: 3");
-
- this.publishProfile.saveConfigFile();
- //NOF.util_logging_ConsoleLogger_global.info("Save aliases: 4");
- } else {
- var sStr = "<" + this.ADVANCED_SETTINGS + ">";
- if (advSetStr.indexOf(sStr) < 0) {
- advSetStr = "<" + this.ADVANCED_SETTINGS + ">"
- + advSetStr + "</" + this.ADVANCED_SETTINGS + ">";
- }
- this.pPublishServer.AdvancedSettings = advSetStr;
- }
-
- this.xmlAdvProp.loadXML( this.getAdvancedSettings().toXML() );
- }
-
- /**
- * get Virtual Folders of publish server
- **/
- methods.getAliases = function () {
- if (this.isGlobal()) {
- this.xmlAdvProp.loadXML( this.getAdvancedSettings().toXML() );
- var node = this.xmlAdvProp.documentElement.selectSingleNode("//virtualFolders");
-
- var sStr = null;
- if (node != null) sStr = node.xml;
- if (sStr == null) sStr = "";
- if ("" == sStr) {
- sStr = "<" + this.VIRTUAL_FOLDERS + ">" + sStr +
- "</" + this.VIRTUAL_FOLDERS + ">";
- }
- //NOF.util_logging_ConsoleLogger_global.info("Get PublishSettingsAliases: " + sStr);
-
- return new NOF.PUBLISH.Aliases(sStr);
- } else {
- var sStr = "<" + this.VIRTUAL_FOLDERS + "></" + this.VIRTUAL_FOLDERS + ">";
- var xmlAliases = NOF.XML.XmlDocument.create();
- xmlAliases.loadXML( sStr );
- var node = xmlAliases.documentElement.selectSingleNode("/" + this.VIRTUAL_FOLDERS);
-
- var aliasIter = this.pPublishServer.GetVirtualFolders();
-
- var aliaslength = aliasIter.Count();
- for (i = 0; i < aliaslength; i++)
- {
- var alias = aliasIter.GetNext();
- if (alias)
- {
- var newVirFold = this.xmlAdvProp.createElement("virtualFolder");
- var newURL = this.xmlAdvProp.createElement("urlPath");
- var newPATH = this.xmlAdvProp.createElement("ftpPath");
- newURL.appendChild(this.xmlAdvProp.createTextNode(alias.URLPath));
- newPATH.appendChild(this.xmlAdvProp.createTextNode(alias.FTPPath));
- newVirFold.appendChild(newURL);
- newVirFold.appendChild(newPATH);
- node.appendChild(newVirFold);
- }
- }
-
- return new NOF.PUBLISH.Aliases(xmlAliases.xml);
- }
- }
-
- /**
- * set Virtual Folders of publish server
- **/
- methods.setAliases = function (/*Aliases*/ aliases) {
- if (this.isGlobal()) {
- var xmlAliases = NOF.XML.XmlDocument.create();
- xmlAliases.loadXML( aliases.toXML() );
- this.xmlAdvProp.loadXML( this.getAdvancedSettings().toXML() );
-
- var node = this.xmlAdvProp.documentElement.selectSingleNode("//virtualFolders");
- var nodeVar = xmlAliases.documentElement.selectSingleNode("/virtualFolders");
- if (node == null) {
- //NOF.util_logging_ConsoleLogger_global.info("Save aliases: as child");
- this.xmlAdvProp.documentElement.appendChild(nodeVar);
- } else {
- //NOF.util_logging_ConsoleLogger_global.info("Save aliases: as node");
- var parNode = node.parentNode;
- parNode.removeChild(node);
- this.xmlAdvProp.documentElement.appendChild(nodeVar);
- //NOF.util_logging_ConsoleLogger_global.info("Save aliases: as node - done");
- //node = nodeVar;
- }
- var advSet = new NOF.PUBLISH.AdvancedSettings(this.xmlAdvProp.xml);
- //advSet.setProperty("virtualFolders", nodeVar.xml);
-
- //NOF.util_logging_ConsoleLogger_global.info("Save aliases: 5");
- this.setAdvancedSettings(advSet);
- //NOF.util_logging_ConsoleLogger_global.info("Save aliases: 6");
- } else {
- var aliasIter = aliases.iterator();
- for (; aliasIter.hasNext();)
- {
- var alias = aliasIter.next();
-
- var origAliasIter = this.pPublishServer.GetVirtualFolders();
-
- var aliaslength = origAliasIter.Count();
- var exists = false;
- for (i = 0; i < aliaslength; i++)
- {
- var aliasOrig = origAliasIter.GetNext();
- if (aliasOrig)
- {
- if (aliasOrig.URLPath == alias.getURL()) {
- //modify
- exists = true;
- aliasOrig.URLPath = alias.getURL();
- aliasOrig.FTPPath = alias.getPath();
- }
- }
- }
- if (!exists) {
- //add
- this.pPublishServer.NewVirtualFolder(alias.getURL(), alias.getPath());
- }
- }
-
- var origAliasIter = this.pPublishServer.GetVirtualFolders();
-
- var aliaslength = origAliasIter.Count();
- for (i = 0; i < aliaslength; i++)
- {
- var aliasOrig = origAliasIter.GetNext();
- if (aliasOrig)
- {
- var exists = false;
-
- var aliasesIter = aliases.iterator();
- for (; aliasesIter.hasNext();)
- {
- var alias = aliasesIter.next();
- if (aliasOrig.URLPath == alias.getURL()) {
- //modify
- exists = true;
- }
- }
-
- if (!exists) {
- //delete
- aliasOrig.Remove();
- }
- }
- }
- }
- }
-
- /**
- *
- **/
- methods.setProperty = function (propName, propValue) {
- eval("this.set" + propName + "(propValue)");
- }
- /**
- *
- **/
- methods.getProperty = function (propName) {
- var propValue = eval("this.get" + propName + "()");
- return propValue;
- }
-
- /**
- * Remove current server.
- **/
- methods.remove = function () {
- if (this.isGlobal())
- this.publishProfile.deleteConfigFile();
- else
- this.pPublishServer.Remove();
- }
-
- /**
- * Get current server.
- **/
- methods.getPublishServer = function () {
- if (this.isGlobal())
- return this.publishProfile;
- else
- return this.pPublishServer;
- }
- }
-
- NOF.PUBLISH.__proto__.PublishServer = NOF_PublishServer;
- }